package com.qianfeng.vhly.youshare.tasks;

import android.os.AsyncTask;
import com.qianfeng.vhly.youshare.utils.HttpTool;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.HashMap;

/**
 * Created with IntelliJ IDEA.
 * User: vhly[FR]
 * Date: 15/2/5
 * Email: vhly@163.com
 */
public class RegisterTask extends AsyncTask<String, Integer, String> {

    @Override
    protected String doInBackground(String... params) {
        String ret = null;

        if(params != null && params.length > 2){
            String name = params[0];
            String pass = params[1];
            String confirmPass = params[2];


            String url = "http://open.doushangshang.com/user/register.php";

            HashMap<String, String> map = new HashMap<String, String>();

            map.put("name", name);
            map.put("pwd", pass);
            map.put("pwd1", confirmPass);

            byte[] bytes = HttpTool.post(url, map);

            if(bytes != null) {
                try {
                    ret = new String(bytes, "UTF-8");
                } catch (UnsupportedEncodingException e) {
                    e.printStackTrace();
                }
            }

        }

        return ret;
    }
}
